<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <canvas id="canvas"></canvas>
    <script>
      const canvas = document.getElementById("canvas");
      const ctx = canvas.getContext("2d");
      const width = window.innerWidth;
      const height = window.innerHeight;
      canvas.width = width;
      canvas.height = height;

      ctx.translate(width / 2, height);
      ctx.scale(1, -1);

      function drawBranch(v0, length, thick, angle) {
        if (length < 10) {
          ctx.beginPath();
          ctx.arc(...v0, 3, 0, 2 * Math.PI);
          ctx.fillStyle = "#763262";
          ctx.fill();
          return;
        }
        ctx.beginPath();
        ctx.moveTo(...v0);
        const v1 = [
          v0[0] + length * Math.cos((angle * Math.PI) / 180),
          v0[1] + length * Math.sin((angle * Math.PI) / 180),
        ];
        ctx.lineTo(...v1);
        ctx.lineWidth = thick;
        ctx.strokestyle = "#333";
        ctx.stroke();

        drawBranch(v1, length * 0.8, thick * 0.8, angle + Math.random() * 30);
        drawBranch(v1, length * 0.8, thick * 0.8, angle - Math.random() * 30);
      }

      drawBranch([0, 0], 200, 10, 90);
    </script>
  </body>
</html>
